package com.stylefeng.guns.modular.shop.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.util.ToolUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Shop;
import com.stylefeng.guns.modular.shop.service.IShopService;

/**
 * 商家管理控制器
 *
 * @author fengshuonan
 * @Date 2018-07-27 16:13:11
 */
@Controller
@RequestMapping("/shop")
public class ShopController extends BaseController {

    private String PREFIX = "/shop/shop/";

    @Autowired
    private IShopService shopService;

    /**
     * 跳转到商家管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "shop.html";
    }

    /**
     * 跳转到添加商家管理
     */
    @RequestMapping("/shop_add")
    public String shopAdd() {
        return PREFIX + "shop_add.html";
    }

    /**
     * 跳转到修改商家管理
     */
    @RequestMapping("/shop_update/{shopId}")
    public String shopUpdate(@PathVariable Integer shopId, Model model) {
        Shop shop = shopService.selectById(shopId);
        model.addAttribute("item",shop);
        LogObjectHolder.me().set(shop);
        return PREFIX + "shop_edit.html";
    }

    /**
     * 获取商家管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {

        return shopService.selectList(null);
    }

    /**
     * 新增商家管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Shop shop) {
        shopService.insert(shop);
        return SUCCESS_TIP;
    }

    /**
     * 删除商家管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer shopId) {
        shopService.deleteById(shopId);
        return SUCCESS_TIP;
    }

    /**
     * 修改商家管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Shop shop) {
        shopService.updateById(shop);
        return SUCCESS_TIP;
    }

    /**
     * 商家管理详情
     */
    @RequestMapping(value = "/detail/{shopId}")
    @ResponseBody
    public Object detail(@PathVariable("shopId") Integer shopId) {
        return shopService.selectById(shopId);
    }
}
